var app = getApp();
const pathUrl = app.globalData.pathUrl;
Page({
  data: {
    pathUrl: pathUrl,
    openId: '',
    proNo: '',
    orderNo: '',
    proIsdb: '', //是否有担保人1是
    proAttList: [], //上传附件列表
    array: ['图片', '视频'],
    array1: ['贷款金额', '附加金额'],
    array14: ['婚姻状况证明', '收入证明', '银行卡流水', '购房合同等其他房产证明材料', '身份证正面', '征信授权书', '签约照片', '购车发票', '合格证', '车辆登记证书', '家访照片', '购车合同证明', '声明', '车辆保险单', '车位认购/租赁合同', '承诺书', '补充说明材料', '代领权证类资料清单', '代领权证委托书', '担保承诺函', '担保确认函', '定金证明', '二手车评估报告', '个人贷记卡定制分期业务申请书', '个人贷款面谈记录', '个人贷款申请表', '个人信贷客户电话核实内容记录表', '个人信贷业务申请资料', '工银信用卡申请表', '共同偿债人承诺书', '购车分期付款代理协议', '购房发票', '关单/进口证明书', '合作机构垫款凭证', '机动车抵押登记质押备案申请表', '机动车业务委托书', '居住/户籍证明', '联网核查结果', '领卡签收单', '汽车专项分期申请表(客户签字)', '牡丹卡分期付款合同', '牡丹信用卡购车消费分期合同', '牡丹信用卡消费分期业务委托扣款、分期授权书', '其他财力证明', '汽车专项分期付款/担保合同', '首付款收据及凭证', '授权委托书(服务费)', '送达方式/地址确认书', '特种转账凭证', '调查报告', '委托协议书', '温馨提示', '信用卡个人营销推荐函', '中国工商银行广东省分行信用卡授信调额审批表', '用卡须知', '逾期还款证明', '职业证明', '个人材料', '中国工商银行信用卡汽车专项分期申请表', '保证书', '身份证反面', '数据查询授权书', '人脸正面照', '授权书签字照片', '房产证', '委托授权书', '抵押权证', '基础资料', '精装修购房及按揭贷款材料', '承保意向书', '履约保险函', '个人承诺函', '资金用途证明资料', '其他贷款材料', '风险控制', '审批要件', '外观前部照', '外观后部照', '内饰照', '内部结构照', '证件照'],
    flag: true,
    isSubmit: true
  },
  onLoad: function (e) {
console.log(e)
    var openId = wx.getStorageSync('openId');
    var proName = e.proName; 
    var orderNo = e.orderNo;
    this.setData({
      openId: openId,
      orderNo: orderNo,
      proName: proName
    })
    wx.setNavigationBarTitle({
      title: proName
    })
    // console.log("proNo:" + proNo)
    this.getProAttList();
  },
  getProAttList: function () {
    var that = this;
    wx.request({
      url: pathUrl + '/rest/fxjProMainController/4' ,
      success: function (res) {
        console.log(res.data)
        if (res.data.ok || res.data.data) {
          var newProAttList = res.data.data.fxjProAttList;
          for (var i = 0; i < newProAttList.length; i++) {
            newProAttList[i].picList = [];
          }
          that.setData({
            proAttList: newProAttList,
            proIsdb: res.data.data.proIsdb
          })
        } else {
          var newProAttList = res.data.data.fxjProAttList;
          newProAttList[0].picList = [];
          that.setData({
            proAttList: newProAttList,
            proIsdb: res.data.data.proIsdb
          })
          // wx.showModal({
          //   title: '提示',
          //   content: '获取数据失败',
          //   confirmColor: '#7aa6d1',
          //   showCancel: false
          // })
        }
      }
    })
  },
  //上传附件图片
  getEnclosurePic: function (e) {
    console.log(e);
    var picIndex = e.currentTarget.dataset.index;
    var attType = e.currentTarget.dataset.atttype;
    var materialCode = e.currentTarget.dataset.number14;
    var materialsType = e.currentTarget.dataset.number;
    if (materialCode == null || materialCode==''){
      wx.showToast({
        title: '请选择材料编码',
        icon:'none'
      })
      return false
    }

    if (materialsType == null || materialsType == '') {
      wx.showToast({
        title: '请选择材料类型',
        icon: 'none'
      })
      return false
    }

    var that = this;
    wx.chooseImage({
      sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有  
      sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有  
      success: function (res) {
        // 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片  
        var tempFilePaths = res.tempFilePaths;
        //启动上传等待中...  
        wx.showToast({
          title: '正在上传...',
          icon: 'loading',
          mask: true,
          duration: 10000
        })
        var uploadImgCount = 0;
        for (var i = 0, h = tempFilePaths.length; i < h; i++) {
          wx.uploadFile({
            url: pathUrl + '/rest/base/upload',
            filePath: tempFilePaths[i],
            name: 'uploadfile_ant',
            formData: {
              sbtype: 'NO',
              filetype: "sb",
              orderNo: that.data.orderNo
            },
            header: {
              "Content-Type": "multipart/form-data"
            },
            success: function (res) {
              console.log(res)
              uploadImgCount++;
              var data = JSON.parse(res.data);
              var proAttListInfo = that.data.proAttList;
              console.log(data)
              proAttListInfo[picIndex].picList.push({
                picUrl: data[0].fileUrl,
                picId: data[0].fileId
              });
              that.setData({
                proAttList: proAttListInfo,
                picId: data[0].fileId,
                picFileName: data[0].fileName,
                picAddress: data[0].fileUrl
              });
                var data = {
                  createBy: that.data.openId,
                  fxjOut01: that.data.orderNo, //订单编号
                  materialCode: that.data.number14,
                  materialsType: that.data.number,
                  downloadMode: '1',
                  demandMateId: that.data.picId,
                  materialsPic: that.data.picAddress,
                  fileName: that.data.picFileName,
                };
                console.log(data)
              wx.request({
                url: pathUrl + '/rest/hrfqjj03Controller',
                data: data,
                method: 'POST',
                success: function (res) {
                  console.log(res)
                }
              })
              if (uploadImgCount == tempFilePaths.length) {
                wx.hideToast();
              }
            },
            fail: function (res) {
              wx.hideToast();
              wx.showModal({
                title: '错误提示',
                content: '上传图片失败',
                showCancel: false
              })
            }
          });
        }
      }
    });
  },
  //删除上传附件图片
  deletePic: function (e) {
    var that = this;
    var index = e.currentTarget.dataset.index;
    var imgIdx = e.currentTarget.dataset.imgIdx;
    var deletPicId = that.data.proAttList[index].picList[imgIdx].picId;
    if (that.data.flag) {
      that.data.proAttList[index].picList.splice(imgIdx, 1);
      that.setData({
        proAttList: that.data.proAttList,
        flag: false
      })
    }
    wx.request({
      url: pathUrl + '/rest/base/delfile/' + deletPicId,
      success: function (res) {
        if (res.data.ok || res.data.data) {
          that.setData({
            flag: true
          })
        } else {
          wx.showModal({
            title: '提示',
            content: '获取数据失败',
            confirmColor: '#7aa6d1',
            showCancel: false
          })
        }
      }
    })
  },
  bindRelationship14: function (e) {
    var index = e.detail.value;
    var orderPeriod14 = this.data.array14[index];
    var number14 = Number(index) + 1;
    if (index == '0') {
      this.setData({
        number14: 'hyzkzm',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '1') {
      this.setData({
        number14: 'srzm',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '2') {
      this.setData({
        number14: 'yhls',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '3') {
      this.setData({
        number14: 'gfhtdqtfczm',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '4') {
      this.setData({
        number14: 'sfzzm',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '5') {
      this.setData({
        number14: 'zxsqs',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '6') {
      this.setData({
        number14: 'qyzp',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '7') {
      this.setData({
        number14: 'gcfp',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '8') {
      this.setData({
        number14: 'hgz',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '9') {
      this.setData({
        number14: 'cldjzs',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '10') {
      this.setData({
        number14: 'jfzp',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '11') {
      this.setData({
        number14: 'gchtzm',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '12') {
      this.setData({
        number14: 'sm',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '13') {
      this.setData({
        number14: 'clbxd',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '14') {
      this.setData({
        number14: 'cwrg',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '15') {
      this.setData({
        number14: 'cns',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '16') {
      this.setData({
        number14: 'deykqksm',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '17') {
      this.setData({
        number14: 'dlqzlzlqd',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '18') {
      this.setData({
        number14: 'dlqzwts',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '19') {
      this.setData({
        number14: 'dbcnh',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '20') {
      this.setData({
        number14: 'dbqrh',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '21') {
      this.setData({
        number14: 'djzm',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '22') {
      this.setData({
        number14: 'escpgbg',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '23') {
      this.setData({
        number14: 'grdjkdzfqywsqs',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '24') {
      this.setData({
        number14: 'grdkmtjl',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '25') {
      this.setData({
        number14: 'grdksqb',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '26') {
      this.setData({
        number14: 'grxdkhdhhsnrjlb',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '27') {
      this.setData({
        number14: 'grxdywsqzl',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '28') {
      this.setData({
        number14: 'gyxyksqb',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '29') {
      this.setData({
        number14: 'gtczrcns',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '30') {
      this.setData({
        number14: 'gcfqfkdlxy',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '31') {
      this.setData({
        number14: 'gffp',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '32') {
      this.setData({
        number14: 'gdjkzms',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '33') {
      this.setData({
        number14: 'hzjgdkpz',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '34') {
      this.setData({
        number14: 'jdcdydjzybasqb',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '35') {
      this.setData({
        number14: 'jdcywwts',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '36') {
      this.setData({
        number14: 'jzhjzm',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '37') {
      this.setData({
        number14: 'lwhcjg',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '38') {
      this.setData({
        number14: 'lkqsd',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '39') {
      this.setData({
        number14: 'mdcdydcscspb',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '40') {
      this.setData({
        number14: 'mdkfqfkht',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '41') {
      this.setData({
        number14: 'mdxykgcxffqhkht',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '42') {
      this.setData({
        number14: 'mdxykxffqywwtkk',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '43') {
      this.setData({
        number14: 'qtclzm',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '44') {
      this.setData({
        number14: 'qczxfqfkdbht',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '45') {
      this.setData({
        number14: 'sfksjjpz',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '46') {
      this.setData({
        number14: 'sqwtsfwf',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '47') {
      this.setData({
        number14: 'sdfsdzqrs',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '48') {
      this.setData({
        number14: 'tzzzpz',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '49') {
      this.setData({
        number14: 'dcbg',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '50') {
      this.setData({
        number14: 'wtxys',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '51') {
      this.setData({
        number14: 'wxts',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '52') {
      this.setData({
        number14: 'xykgryxtjh',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '53') {
      this.setData({
        number14: 'xyksxtesqb',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '54') {
      this.setData({
        number14: 'ykxz',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '55') {
      this.setData({
        number14: 'yqhkzm',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '56') {
      this.setData({
        number14: 'zyzm',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '57') {
      this.setData({
        number14: 'zggsyhqczxfqspdgd',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '58') {
      this.setData({
        number14: 'zggsyhxykqczxfqsqb',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '59') {
      this.setData({
        number14: 'bzs',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '60') {
      this.setData({
        number14: 'sfzfm',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '61') {
      this.setData({
        number14: 'sjcxsqs',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '62') {
      this.setData({
        number14: 'rlzmz',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '63') {
      this.setData({
        number14: 'zxsqszp',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '64') {
      this.setData({
        number14: 'fcz',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '65') {
      this.setData({
        number14: 'wtsqs',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '66') {
      this.setData({
        number14: 'dyqz',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '67') {
      this.setData({
        number14: 'grjczl',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '68') {
      this.setData({
        number14: 'jzxgfajcl',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '69') {
      this.setData({
        number14: 'cbyxs',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '70') {
      this.setData({
        number14: 'lyxbh',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '71') {
      this.setData({
        number14: 'grcnh',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '72') {
      this.setData({
        number14: 'zjytzmcl',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '73') {
      this.setData({
        number14: 'WGDCL',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '74') {
      this.setData({
        number14: 'fxkzcl',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '75') {
      this.setData({
        number14: 'spyjcl',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '76') {
      this.setData({
        number14: 'wgqbz',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '77') {
      this.setData({
        number14: 'wghbz',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '78') {
      this.setData({
        number14: 'nsz',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '79') {
      this.setData({
        number14: 'nbjgz',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }
    if (index == '80') {
      this.setData({
        number14: 'zjz',
        pickerIndex14: index,
        orderPeriod14: orderPeriod14
      })
    }

  },
  bindRelationship: function (e) {
    var index = e.detail.value;
    var orderPeriod = this.data.array[index];
    var number = null;
    this.setData({
      number: index,
      pickerIndex: index,
      orderPeriod: orderPeriod
    })

  },
  bindRelationship1: function (e) {
    var index = e.detail.value;
    var orderPeriod1 = this.data.array1[index];
    var number1 = Number(index) + 1;
    this.setData({
      number1: number1,
      pickerIndex1: index,
      orderPeriod1: orderPeriod1
    })
  },
  cocomId: function (e) {
    this.setData({
      cocomId: e.detail.value
    })
  },
  cocomInterestNo: function (e) {
    this.setData({
      cocomInterestNo: e.detail.value
    })
  },
  cocomReceiveAmt: function (e) {
    this.setData({
      cocomReceiveAmt: e.detail.value
    })
  },

  submitBtn1: function () {
    wx.navigateBack({
      delta: 1

    })
  },
  submitBtn: function () {
    var that = this;
    if (that.data.isSubmit) {
      that.setData({
        isSubmit: false
      });
      var data = {
        cocomId: that.data.cocomId,
        cocomInterestFlag: that.data.number,
        cocomInterestNo: that.data.cocomInterestNo,
        cocomReceiveAmt: that.data.cocomReceiveAmt,
        cocomReceiveType: that.data.number1,
        fxjOut01: that.data.orderNo,
        fxjOut02: that.data.type,

      };
      console.log("data:" + JSON.stringify(data));
      wx.request({
        url: pathUrl + '/rest/hrfqjj04Controller',
        data: data,
        method: 'POST',
        success: function (res) {
          console.log(res.data)
          if (res.data.ok) {
            that.setData({
              isSubmit: true
            });
            wx.showToast({
              title: '提交成功',
              duration: 1000,
              mask: true,
              success: function () {
                setTimeout(function () {
                  // wx.switchTab({
                  //   url: "/pages/index/index"
                  // })
                  wx.navigateBack({
                    delta: 1
                  })
                }, 1000);
              }
            })
          } else {
            that.setData({
              isSubmit: true
            });
            wx.showToast({
              title: '提交失败',
              icon: 'none',
              mask: true,
              duration: 1000
            })
          }
        }
      })
    } else {
      wx.showToast({
        title: '请勿重复提交',
        icon: 'none',
        mask: true,
        duration: 1000
      })
    }
  },

  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})